package com.example.mall.controller;

import com.example.mall.util.ResultVo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;

/**
 * @author ：Dongdequan
 * @date ：Created in 2022/6/1 11:13
 * @modified By：
 */
public class BaseController {

    public Long getUserId(String token){
        Jws<Claims> claimsJws = Jwts.parserBuilder().requireSubject("JWT")
                .setSigningKey(ResultVo.SECRET_KEY).build().parseClaimsJws(token);
        Claims body = claimsJws.getBody();
        Long userId = body.get("userId", Long.class);
        return userId;
    }
}
